
let ivcs = require('./dist/ivcs');
let io = require('socket.io-client');
//测试的服务器地址
let url = 
//"https://192.168.31.186"
"https://ivcs-showcase.zealcomm.cn";
function testOneRobot(){
    let robot = new ivcs.agent();
    robot.init(url,'robotsun007','zealcomm@ivcs_robot2021','1',null,(success)=>{
        console.log('robot init,success',success);
        robot.login((success)=>{
            console.log('login success',success);
            // let para = {
            //     groups:[]
            //   };
            // robot.checkIn(para,(s)=>{
            //    console.log('checkin success',s);
            // },(e)=>{
            //     console.log('checkin error',e)
            // });
            robot.onRing((ack)=>{
                console.log(ack);
                robot.answer((success)=>{
                    console.log('answer success',success);
                    robot.onCcsDrop((resp)=>{
                         console.log('ccs sio error',resp);
                         robot.hangup((s)=>{
                             console.log('11hang up success',s,new Date());
                         },(e)=>{
                            console.log('11hang up e',e,new Date());
                         });
                    });
                    robot.onTextMessage((data)=>{
                        console.log('text message',data);
                    });
                },(e)=>{
                    console.log('answer ring error',e);
                    robot.hangup((s)=>{
                        console.log('22hang up success',s,new Date());
                    },(e)=>{
                       console.log('22hang up e',e,new Date());
                    });
                },(ccsTicketFailed)=>{
                    console.log('ccsTicketFailed',ccsTicketFailed);
                    robot.hangup((s)=>{
                        console.log('33hang up success',s,new Date());
                    },(e)=>{
                       console.log('33hang up e',e,new Date());
                    });
                });
            });
            robot.onCancelRing((ack)=>{
                console.log('onCancelRing',ack);
            });
            robot.onDrop((ack)=>{
                console.log('ams sio on drop error',ack);
            });
            robot.ready((success)=>{
                console.log('ready result',success);
                let para = {
                    groups:[12]//输入init成功后返回的groupsList分组里的id
                };
                robot.checkIn(para,(s)=>{
                    console.log('checkin result',s);
                },(error)=>{
                    console.log('checkIn error',error);
                })
            },(error)=>{
                console.log(error);
            });
        },(error)=>{
            console.log(error);
        },(status,amsTicketInvalid)=>{
            console.log('amsTicketInvalid error,',status,amsTicketInvalid);
        });
    },(error)=>{
        console.log('robot init error',error)
    });
}

testOneRobot();







